package com.xyh.web;

import com.xyh.pojo.PageRequest;
import com.xyh.pojo.Type;
import com.xyh.service.BlogService;
import com.xyh.service.TypeService;
import com.xyh.vo.BlogQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
public class TypeShowController {
    @Autowired
    private TypeService typeService;
    @Autowired
    private BlogService blogService;
    @GetMapping("/types/{id}")
    public String types(PageRequest pageRequest,@PathVariable Long id, Model model){
        List<Type> types = typeService.getTypeTop(10000);
        if (id==-1) {
            id=types.get(0).getId();
        }
        model.addAttribute("types", types);
        BlogQuery blogQuery = new BlogQuery();
        blogQuery.setTypeId(id);
        model.addAttribute("page", blogService.getPageByCondition(pageRequest, blogQuery));
        model.addAttribute("activeTypeId", id);
        return "types";
    }
}
